package com.fire.activiti.activitidb.process.util;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author Mr.Fire
 * @date 2021/12/21
 * @desc
 */
public class DataBaseUtil {

    public static String getDatabaseType(Connection connection) {
        try {
            String url = connection.getMetaData().getURL();
            String subUrl = url.substring(5);
            if (subUrl.startsWith("oracle")){
                return "oracle";
            }else if(subUrl.startsWith("mysql")){
                return "mysql";
            }else if(subUrl.startsWith("postgresql")){
                return "postgresql";
            }else if(subUrl.startsWith("informix-sqli")){
                return "gbase";
            }else if(subUrl.startsWith("hana")){
                return "hana";
            }else if(subUrl.startsWith("dm")){
                return "dm";
            }else if(subUrl.startsWith("gaussdb")){
                return "gaussdb";
            }
        } catch (SQLException e) {
           throw new RuntimeException(e);
        }
        return null;
    }
}
